package com.itheima.demo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo01 {

    public static void main(String[] args) {

        Student s1 = new Student("陈粒",29);
        Student s2 = new Student("陈奕迅",40);
        Student s3 = new Student("陈数",38);

        List<Student> list = new ArrayList<>();

        list.add(s1);
        list.add(s2);
        list.add(s3);

        for (int i = 0; i < list.size(); i++) {

            Student student = list.get(i);
            System.out.println(student.getName()+"   "+student.getAge());
        }

        System.out.println("-----------------------------------------------");

        for(Student a : list){
            System.out.println(a.getName()+"   "+a.getAge());
        }

        System.out.println("----------------------------------------------");

        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next.getName()+"   "+next.getAge());

        }

        System.out.println("-------------------------------------------");

        list.forEach(student -> {
            System.out.println(student.getName()+"   "+student.getAge());
        });


    }
}
